package com.heima.kafka.test.listener;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.test.pojo.User;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * Author: Administrator
 * CreateTime: 2024/10/2
 * Project: heima-leadnews
 */
@Component
public class HelloListener {
    @KafkaListener(topics = {"kafka-hello"})
    public void onMessage(String message) {
        if (message != null) System.out.println(message);
    }

    @KafkaListener(topics = {"kafka-obj"})
    public void onMessageIfObject(String message) {
        if (StringUtils.hasText(message)) {
            User user = JSON.parseObject(message, User.class);
            System.out.println(user);
        }
    }
}
